package com.woniu.gym.controller;


import com.woniu.core.util.JwtUtil;
import com.woniu.core.util.PageInfo;
import com.woniu.core.util.RedisUtil;
import com.woniu.core.util.Result;
import com.woniu.gym.dto.FindGymBaseDto;
import com.woniu.gym.dto.GymBaseDto;
import com.woniu.gym.form.FindGymBaseByAdminForm;
import com.woniu.gym.form.FindGymBaseByIdForm;
import com.woniu.gym.form.ModifyGymInformationForm;
import com.woniu.gym.model.TGymBase;
import com.woniu.gym.service.TGymBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴彦祖
 * @since 2024年04月02日
 */
@RestController
@RequestMapping("/tGymBase")
@Api(tags = "场馆基础信息管理接口")
public class TGymBaseController {

    @Resource
    private TGymBaseService tGymBaseService;
    @Resource
    private RedisUtil redisUtil;
    @ApiOperation("根据gymNum查询场馆基础信息")
    @GetMapping("/findGymBaseByNum/{gymNum}")
    public Result<GymBaseDto> findGymBaseByNum(@PathVariable("gymNum") String gymNum){
        GymBaseDto dto = tGymBaseService.findGymBaseByNum(gymNum);
        return Result.getResult(GymBaseDto.class).setMsg("查询成功").setData(dto);
    }
    @ApiOperation("用户评价后根据场馆gymNum修改场馆评分")
    @GetMapping("/modifyGymMark/{gymNum}/{gymMark}")
    public Result<TGymBase> modifyGymMark(@PathVariable ("gymNum") String gymNum, @PathVariable ("gymMark") Double gymMark){
        TGymBase gymBase = tGymBaseService.modifyGymMark(gymNum,gymMark);
        return Result.getResult(TGymBase.class).setMsg("修改成功").setData(gymBase);
    }
    @ApiOperation("根据gymId查询该账号下的所有已申请通过的场馆")
    @GetMapping("/findGymBaseById.gym")
    public Result findGymBaseById(FindGymBaseByIdForm form, @RequestHeader String token) throws Exception {
        String refreshToken = redisUtil.get(token);
        Integer gymId = (Integer) JwtUtil.parseToken(refreshToken, 4).get("gymId");
        form.setGymId(gymId);
        PageInfo<FindGymBaseDto> dto = tGymBaseService.findGymBaseById(form);
        return Result.getResult(PageInfo.class).setMsg("查询成功").setData(dto);
    }
    @ApiOperation("管理员查询所有已申请通过的场馆")
    @GetMapping("/findGymBaseByAdmin.admin")
    public Result findGymBaseByAdmin(FindGymBaseByAdminForm form) throws Exception {
        PageInfo<FindGymBaseDto> dto = tGymBaseService.findGymBaseByAdmin(form);
        return Result.getResult(PageInfo.class).setMsg("查询成功").setData(dto);
    }
    @ApiOperation("根据gymNum修改自己的场馆基础信息")
    @PostMapping("/modifyGymByNum.gym")
    public Result<TGymBase> modifyGymByNum(ModifyGymInformationForm form){
        TGymBase tGymBase = tGymBaseService.modifyGymByNum(form);
        return Result.getResult(TGymBase.class).setMsg("修改成功").setData(tGymBase);
    }
    @ApiOperation("订单支付成功后根据gymNum修改店铺状态为1正常,支付状态为1已支付")
    @GetMapping("/modifyGymState/{gymNum}")
    public Result<TGymBase> modifyGymState(@PathVariable("gymNum") String gymNum){
        TGymBase tGymBase = tGymBaseService.modifyGymState(gymNum);
        return Result.getResult(TGymBase.class).setMsg("修改成功").setData(tGymBase);
    }



}

